package com.zlm.spider.pipeline;


import com.zlm.spider.entity.Job;
import com.zlm.spider.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * Author: Harbour
 * Date: 2021-04-13 23:37
 * Desc:
 */
@Component
public class SpringDataPipeline implements Pipeline {

    @Autowired
    private JobService jobService;

    @Override
    public void process(ResultItems resultItems, Task task) {
        Job job = resultItems.get("job");

        if (job != null) {
            jobService.save(job);
            System.out.println(job.toString());
        }
    }
}
